package person.learn.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import person.learn.conf.exitcode.ExitCodeConfig;
import person.learn.util.ApplicationContextUtil;

/**
 * Created by barton on 16-1-25.
 * 1.用来测试ExitCodeGenerator接口
 * 2.使用@RestController注解，请尽量遵循RESTFUL 接口设计规范
 */
@RestController
@RequestMapping("/exit")
public class ExitController {

    @Autowired
    private ApplicationContextUtil applicationContextUtil;

    /**
     * 调用此接口手动结束应用
     *
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<Void> exit() {

        SpringApplication.exit(applicationContextUtil.getApplicationContext(), new ExitCodeConfig());

        ResponseEntity<Void> responseEntity = new ResponseEntity<>(
                HttpStatus.OK);

        return responseEntity;
    }
}
